package com.yfp.operation.api.factory;

import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderV3Result;
import com.yfp.common.core.domain.R;
import com.yfp.operation.api.RemoteGroupService;
import com.yfp.operation.domain.EnterpriseVO;
import com.yfp.operation.domain.GroupRegisterBody;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
public class RemoteGroupFallbackFactory implements FallbackFactory<RemoteGroupService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteGroupFallbackFactory.class);

    @Override
    public RemoteGroupService create(Throwable throwable) {
        log.error("group团餐服务调用失败:{}", throwable.getMessage());
        return new RemoteGroupService() {

            @Override
            public R<WxPayUnifiedOrderV3Result.JsapiResult> register(GroupRegisterBody groupRegisterBody, String source) {
                log.error("调用{}异常:{}", "register", throwable.getMessage());
                return R.fail(throwable.getMessage());
            }

            @Override
            public R<EnterpriseVO> getEnterpriseUserByUserId(Long userId, String source) {
                log.error("调用{}异常:{}", "getEnterpriseUserByUserId", throwable.getMessage());
                return R.fail("获取用户信息异常：" + throwable.getMessage());
            }

            @Override
            public R<Void> updateFinishTime(String enterpriseOrderSn) {
                log.error("调用{}异常:{}", "updateFinishTime", throwable.getMessage());
                return R.fail(throwable.getMessage());
            }
        };
    }
}